package com.jqb.sturts2lab02.action;

import com.jqb.struts2lab02.bean.User;
import com.jqb.struts2lab02.exception.PasswordException;
import com.jqb.struts2lab02.exception.UsernameException;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginExceptionAction extends ActionSupport {

	private static final long serialVersionUID = 1L;
	
	private User user;

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
	
	@Override
	public String execute() throws Exception {
		
		if(!user.getUsername().equals("admin")){
			
			ActionContext.getContext().put("msg", "用户名不存在");
			throw new UsernameException("用户名不存在");
			
		}else if(!user.getPassword().equals("password")){
			
			ActionContext.getContext().put("msg", "密码错误");
			throw new PasswordException("密码错误");
			
		}else{
			ActionContext.getContext().put("msg", this.getText("welcome",new String[]{user.getUsername()}));
		}
		return SUCCESS;
	}

}
